package com.example.securityservice.config;

import feign.RequestInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.client.OAuth2ClientContext;
import org.springframework.security.oauth2.common.OAuth2AccessToken;

/**
 * 自定义openfeign在请求头添加token
 */
/*@Configuration
public class FeignSecurityConfig {
    @Bean
    public RequestInterceptor oauth2FeignRequestInterceptor(OAuth2ClientContext oauth2ClientContext) {
        return template -> {
            OAuth2AccessToken accessToken = oauth2ClientContext.getAccessToken();
            if (accessToken != null) {
                String tokenValue = accessToken.getValue();
                template.header("Authorization", "Bearer " + tokenValue);
            }
        };
    }
}*/
